package cn.monkey.config;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticSearchConfig {
    @Value("${es.host}")
    private String host="localhost";

    @Value("${es.port}")
    private Integer port=9200;

    @Bean
    ElasticsearchClient elasticsearchClient(){
        RestClient client = RestClient.builder(new HttpHost(host, port, "http")).build();
        ElasticsearchTransport e = new RestClientTransport(client, new JacksonJsonpMapper());
        return new ElasticsearchClient(e);
    }
}
